package com.拷贝;

class Boy{
    String name;
    String brother; //弟弟长度
    public Boy(String name,String brother){
        this.name = name;
        this.brother = brother;
    }

    @Override
    public String toString() {
        return "Boy{" +
                "name='" + name + '\'' +
                ", brother='" + brother + '\'' +
                '}';
    }
}
class Girl implements Cloneable{
    String name;
    Boy boy;
    String ass; //臀围
    public Girl(String name,String ass,Boy boy){
        this.name = name;
        this.ass = ass;
        this.boy = boy;
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    @Override
    public String toString() {
        return "Girl{" +
                "name='" + name + '\'' +
                ", boy=" + boy +
                ", ass='" + ass + '\'' +
                '}';
    }
}

/**
 * 浅拷贝对于引用类型无效。当引用类型改变的时候，源对象和目标都会改变
 */
public class 浅拷贝 {
    public static void main(String[] args) throws Exception {
        Boy boy = new Boy("秦始皇","18cm");
        Girl girl = new Girl("皇妃","50cm",boy);
        Girl girl2 = (Girl)girl.clone();

        girl2.boy.name = "黑人兄弟";
        girl2.name="公主";
        System.out.println(girl2.toString());
        System.out.println(girl.toString());
    }
}
